Option Strict On
Option Explicit On 

Public Class FTable
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnApply As System.Windows.Forms.Button
    Friend WithEvents btnOk As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents UTable1 As Avand.UTable
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents btnAdvanced As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FTable))
        Me.btnApply = New System.Windows.Forms.Button
        Me.btnOk = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.UTable1 = New Avand.UTable
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.btnAdvanced = New System.Windows.Forms.Button
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnApply
        '
        Me.btnApply.AccessibleDescription = resources.GetString("btnApply.AccessibleDescription")
        Me.btnApply.AccessibleName = resources.GetString("btnApply.AccessibleName")
        Me.btnApply.Anchor = CType(resources.GetObject("btnApply.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnApply.BackgroundImage = CType(resources.GetObject("btnApply.BackgroundImage"), System.Drawing.Image)
        Me.btnApply.Dock = CType(resources.GetObject("btnApply.Dock"), System.Windows.Forms.DockStyle)
        Me.btnApply.Enabled = CType(resources.GetObject("btnApply.Enabled"), Boolean)
        Me.btnApply.FlatStyle = CType(resources.GetObject("btnApply.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnApply.Font = CType(resources.GetObject("btnApply.Font"), System.Drawing.Font)
        Me.btnApply.Image = CType(resources.GetObject("btnApply.Image"), System.Drawing.Image)
        Me.btnApply.ImageAlign = CType(resources.GetObject("btnApply.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnApply.ImageIndex = CType(resources.GetObject("btnApply.ImageIndex"), Integer)
        Me.btnApply.ImeMode = CType(resources.GetObject("btnApply.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnApply.Location = CType(resources.GetObject("btnApply.Location"), System.Drawing.Point)
        Me.btnApply.Name = "btnApply"
        Me.btnApply.RightToLeft = CType(resources.GetObject("btnApply.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnApply.Size = CType(resources.GetObject("btnApply.Size"), System.Drawing.Size)
        Me.btnApply.TabIndex = CType(resources.GetObject("btnApply.TabIndex"), Integer)
        Me.btnApply.Text = resources.GetString("btnApply.Text")
        Me.btnApply.TextAlign = CType(resources.GetObject("btnApply.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnApply.Visible = CType(resources.GetObject("btnApply.Visible"), Boolean)
        '
        'btnOk
        '
        Me.btnOk.AccessibleDescription = resources.GetString("btnOk.AccessibleDescription")
        Me.btnOk.AccessibleName = resources.GetString("btnOk.AccessibleName")
        Me.btnOk.Anchor = CType(resources.GetObject("btnOk.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnOk.BackgroundImage = CType(resources.GetObject("btnOk.BackgroundImage"), System.Drawing.Image)
        Me.btnOk.Dock = CType(resources.GetObject("btnOk.Dock"), System.Windows.Forms.DockStyle)
        Me.btnOk.Enabled = CType(resources.GetObject("btnOk.Enabled"), Boolean)
        Me.btnOk.FlatStyle = CType(resources.GetObject("btnOk.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnOk.Font = CType(resources.GetObject("btnOk.Font"), System.Drawing.Font)
        Me.btnOk.Image = CType(resources.GetObject("btnOk.Image"), System.Drawing.Image)
        Me.btnOk.ImageAlign = CType(resources.GetObject("btnOk.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnOk.ImageIndex = CType(resources.GetObject("btnOk.ImageIndex"), Integer)
        Me.btnOk.ImeMode = CType(resources.GetObject("btnOk.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnOk.Location = CType(resources.GetObject("btnOk.Location"), System.Drawing.Point)
        Me.btnOk.Name = "btnOk"
        Me.btnOk.RightToLeft = CType(resources.GetObject("btnOk.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnOk.Size = CType(resources.GetObject("btnOk.Size"), System.Drawing.Size)
        Me.btnOk.TabIndex = CType(resources.GetObject("btnOk.TabIndex"), Integer)
        Me.btnOk.Text = resources.GetString("btnOk.Text")
        Me.btnOk.TextAlign = CType(resources.GetObject("btnOk.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnOk.Visible = CType(resources.GetObject("btnOk.Visible"), Boolean)
        '
        'btnCancel
        '
        Me.btnCancel.AccessibleDescription = resources.GetString("btnCancel.AccessibleDescription")
        Me.btnCancel.AccessibleName = resources.GetString("btnCancel.AccessibleName")
        Me.btnCancel.Anchor = CType(resources.GetObject("btnCancel.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnCancel.BackgroundImage = CType(resources.GetObject("btnCancel.BackgroundImage"), System.Drawing.Image)
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Dock = CType(resources.GetObject("btnCancel.Dock"), System.Windows.Forms.DockStyle)
        Me.btnCancel.Enabled = CType(resources.GetObject("btnCancel.Enabled"), Boolean)
        Me.btnCancel.FlatStyle = CType(resources.GetObject("btnCancel.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnCancel.Font = CType(resources.GetObject("btnCancel.Font"), System.Drawing.Font)
        Me.btnCancel.Image = CType(resources.GetObject("btnCancel.Image"), System.Drawing.Image)
        Me.btnCancel.ImageAlign = CType(resources.GetObject("btnCancel.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnCancel.ImageIndex = CType(resources.GetObject("btnCancel.ImageIndex"), Integer)
        Me.btnCancel.ImeMode = CType(resources.GetObject("btnCancel.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnCancel.Location = CType(resources.GetObject("btnCancel.Location"), System.Drawing.Point)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.RightToLeft = CType(resources.GetObject("btnCancel.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnCancel.Size = CType(resources.GetObject("btnCancel.Size"), System.Drawing.Size)
        Me.btnCancel.TabIndex = CType(resources.GetObject("btnCancel.TabIndex"), Integer)
        Me.btnCancel.Text = resources.GetString("btnCancel.Text")
        Me.btnCancel.TextAlign = CType(resources.GetObject("btnCancel.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnCancel.Visible = CType(resources.GetObject("btnCancel.Visible"), Boolean)
        '
        'UTable1
        '
        Me.UTable1.AccessibleDescription = resources.GetString("UTable1.AccessibleDescription")
        Me.UTable1.AccessibleName = resources.GetString("UTable1.AccessibleName")
        Me.UTable1.Anchor = CType(resources.GetObject("UTable1.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.UTable1.AutoScroll = CType(resources.GetObject("UTable1.AutoScroll"), Boolean)
        Me.UTable1.AutoScrollMargin = CType(resources.GetObject("UTable1.AutoScrollMargin"), System.Drawing.Size)
        Me.UTable1.AutoScrollMinSize = CType(resources.GetObject("UTable1.AutoScrollMinSize"), System.Drawing.Size)
        Me.UTable1.BackgroundImage = CType(resources.GetObject("UTable1.BackgroundImage"), System.Drawing.Image)
        Me.UTable1.Dock = CType(resources.GetObject("UTable1.Dock"), System.Windows.Forms.DockStyle)
        Me.UTable1.Enabled = CType(resources.GetObject("UTable1.Enabled"), Boolean)
        Me.UTable1.Font = CType(resources.GetObject("UTable1.Font"), System.Drawing.Font)
        Me.UTable1.ImeMode = CType(resources.GetObject("UTable1.ImeMode"), System.Windows.Forms.ImeMode)
        Me.UTable1.Location = CType(resources.GetObject("UTable1.Location"), System.Drawing.Point)
        Me.UTable1.Name = "UTable1"
        Me.UTable1.RightToLeft = CType(resources.GetObject("UTable1.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.UTable1.Size = CType(resources.GetObject("UTable1.Size"), System.Drawing.Size)
        Me.UTable1.TabIndex = CType(resources.GetObject("UTable1.TabIndex"), Integer)
        Me.UTable1.Visible = CType(resources.GetObject("UTable1.Visible"), Boolean)
        '
        'Panel1
        '
        Me.Panel1.AccessibleDescription = resources.GetString("Panel1.AccessibleDescription")
        Me.Panel1.AccessibleName = resources.GetString("Panel1.AccessibleName")
        Me.Panel1.Anchor = CType(resources.GetObject("Panel1.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.Panel1.AutoScroll = CType(resources.GetObject("Panel1.AutoScroll"), Boolean)
        Me.Panel1.AutoScrollMargin = CType(resources.GetObject("Panel1.AutoScrollMargin"), System.Drawing.Size)
        Me.Panel1.AutoScrollMinSize = CType(resources.GetObject("Panel1.AutoScrollMinSize"), System.Drawing.Size)
        Me.Panel1.BackgroundImage = CType(resources.GetObject("Panel1.BackgroundImage"), System.Drawing.Image)
        Me.Panel1.Controls.Add(Me.UTable1)
        Me.Panel1.Dock = CType(resources.GetObject("Panel1.Dock"), System.Windows.Forms.DockStyle)
        Me.Panel1.Enabled = CType(resources.GetObject("Panel1.Enabled"), Boolean)
        Me.Panel1.Font = CType(resources.GetObject("Panel1.Font"), System.Drawing.Font)
        Me.Panel1.ImeMode = CType(resources.GetObject("Panel1.ImeMode"), System.Windows.Forms.ImeMode)
        Me.Panel1.Location = CType(resources.GetObject("Panel1.Location"), System.Drawing.Point)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.RightToLeft = CType(resources.GetObject("Panel1.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.Panel1.Size = CType(resources.GetObject("Panel1.Size"), System.Drawing.Size)
        Me.Panel1.TabIndex = CType(resources.GetObject("Panel1.TabIndex"), Integer)
        Me.Panel1.Text = resources.GetString("Panel1.Text")
        Me.Panel1.Visible = CType(resources.GetObject("Panel1.Visible"), Boolean)
        '
        'btnAdvanced
        '
        Me.btnAdvanced.AccessibleDescription = resources.GetString("btnAdvanced.AccessibleDescription")
        Me.btnAdvanced.AccessibleName = resources.GetString("btnAdvanced.AccessibleName")
        Me.btnAdvanced.Anchor = CType(resources.GetObject("btnAdvanced.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnAdvanced.BackgroundImage = CType(resources.GetObject("btnAdvanced.BackgroundImage"), System.Drawing.Image)
        Me.btnAdvanced.Dock = CType(resources.GetObject("btnAdvanced.Dock"), System.Windows.Forms.DockStyle)
        Me.btnAdvanced.Enabled = CType(resources.GetObject("btnAdvanced.Enabled"), Boolean)
        Me.btnAdvanced.FlatStyle = CType(resources.GetObject("btnAdvanced.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnAdvanced.Font = CType(resources.GetObject("btnAdvanced.Font"), System.Drawing.Font)
        Me.btnAdvanced.Image = CType(resources.GetObject("btnAdvanced.Image"), System.Drawing.Image)
        Me.btnAdvanced.ImageAlign = CType(resources.GetObject("btnAdvanced.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnAdvanced.ImageIndex = CType(resources.GetObject("btnAdvanced.ImageIndex"), Integer)
        Me.btnAdvanced.ImeMode = CType(resources.GetObject("btnAdvanced.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnAdvanced.Location = CType(resources.GetObject("btnAdvanced.Location"), System.Drawing.Point)
        Me.btnAdvanced.Name = "btnAdvanced"
        Me.btnAdvanced.RightToLeft = CType(resources.GetObject("btnAdvanced.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnAdvanced.Size = CType(resources.GetObject("btnAdvanced.Size"), System.Drawing.Size)
        Me.btnAdvanced.TabIndex = CType(resources.GetObject("btnAdvanced.TabIndex"), Integer)
        Me.btnAdvanced.Text = resources.GetString("btnAdvanced.Text")
        Me.btnAdvanced.TextAlign = CType(resources.GetObject("btnAdvanced.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnAdvanced.Visible = CType(resources.GetObject("btnAdvanced.Visible"), Boolean)
        '
        'FTable
        '
        Me.AcceptButton = Me.btnOk
        Me.AccessibleDescription = resources.GetString("$this.AccessibleDescription")
        Me.AccessibleName = resources.GetString("$this.AccessibleName")
        Me.AutoScaleBaseSize = CType(resources.GetObject("$this.AutoScaleBaseSize"), System.Drawing.Size)
        Me.AutoScroll = CType(resources.GetObject("$this.AutoScroll"), Boolean)
        Me.AutoScrollMargin = CType(resources.GetObject("$this.AutoScrollMargin"), System.Drawing.Size)
        Me.AutoScrollMinSize = CType(resources.GetObject("$this.AutoScrollMinSize"), System.Drawing.Size)
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.CancelButton = Me.btnCancel
        Me.ClientSize = CType(resources.GetObject("$this.ClientSize"), System.Drawing.Size)
        Me.Controls.Add(Me.btnAdvanced)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.btnApply)
        Me.Controls.Add(Me.btnOk)
        Me.Controls.Add(Me.btnCancel)
        Me.Enabled = CType(resources.GetObject("$this.Enabled"), Boolean)
        Me.Font = CType(resources.GetObject("$this.Font"), System.Drawing.Font)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.ImeMode = CType(resources.GetObject("$this.ImeMode"), System.Windows.Forms.ImeMode)
        Me.Location = CType(resources.GetObject("$this.Location"), System.Drawing.Point)
        Me.MaximizeBox = False
        Me.MaximumSize = CType(resources.GetObject("$this.MaximumSize"), System.Drawing.Size)
        Me.MinimizeBox = False
        Me.MinimumSize = CType(resources.GetObject("$this.MinimumSize"), System.Drawing.Size)
        Me.Name = "FTable"
        Me.RightToLeft = CType(resources.GetObject("$this.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.ShowInTaskbar = False
        Me.StartPosition = CType(resources.GetObject("$this.StartPosition"), System.Windows.Forms.FormStartPosition)
        Me.Text = resources.GetString("$this.Text")
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private mChanged As Boolean
    Private mTable As Model10.Table
    Private mPresentation As Model10.Presentation

    Public Event ValueChenged As EventHandler

    Private Sub FTable_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler UTable1.ValueChanged, AddressOf OnValueChanged
    End Sub
    Private Sub btnAdvanced_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdvanced.Click
        Dim frm As New Avand.FDataTable(mPresentation, mTable)
        frm.UDataTable1.txtTableName.Text = UTable1.txtName.Text
        frm.UDataTable1.txtTableName.ReadOnly = True
        frm.showdialog()
        If frm.Changed Then
            btnApply.Enabled = True
            RaiseEvent ValueChenged(Me, New EventArgs)
        End If
        frm = Nothing
    End Sub
    Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click
        Application.DoEvents()
        Cursor.Current = Cursors.WaitCursor
        '----------------------------------
        Try
            Dim tbl As New Model10.Table
            UTable1.Write(tbl)
            If mTable Is Nothing Then
                If Not mPresentation Is Nothing Then mPresentation.Tables.Add(tbl)
                mTable = tbl
            Else
                UTable1.Write(mTable)
            End If
            tbl = Nothing

            mChanged = True
            btnApply.Enabled = False
            RaiseEvent ValueChenged(Me, New EventArgs)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        '----------------------------------
        Cursor.Current = Cursors.Default
    End Sub
    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        btnApply.PerformClick()
        If Not btnApply.Enabled Then DialogResult = DialogResult.OK
    End Sub

    Protected Sub OnValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        btnApply.Enabled = True
        RaiseEvent ValueChenged(Me, New EventArgs)
    End Sub

    Public Property Changed() As Boolean
        Get
            Return mChanged
        End Get
        Set(ByVal Value As Boolean)
            mChanged = Value
        End Set
    End Property
    Public Property Table() As Model10.Table
        Get
            Return mTable
        End Get
        Set(ByVal Value As Model10.Table)
            mTable = Value
        End Set
    End Property
    Public Property Presentation() As Model10.Presentation
        Get
            Return mPresentation
        End Get
        Set(ByVal Value As Model10.Presentation)
            mPresentation = Value
        End Set
    End Property

    Public Sub Fill()
        UTable1.Prepare(mTable)
        If mTable Is Nothing Then
            Dim tbl As New Model10.Table
            UTable1.Read(tbl)
            tbl = Nothing

            UTable1.txtName.Text = mPresentation.GetNewTableName([Global].GetSystemResource("Element.Table"))

            btnApply.Enabled = True
        Else
            UTable1.Read(mTable)

            btnApply.Enabled = False
        End If
        mChanged = False
    End Sub
    Public Sub New(ByVal presentation As Model10.Presentation, ByVal table As Model10.Table)
        MyBase.New()
        InitializeComponent()

        mTable = table
        mPresentation = presentation
        Fill()
    End Sub
End Class
